package cn.edu.ujs.coor.repository.relation;

import cn.edu.ujs.coor.model.ProjectGroupRelation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ProjectGroupRelationRepository extends JpaRepository<ProjectGroupRelation, String>, JpaSpecificationExecutor<ProjectGroupRelation> {

    /**
     * 根据项目编号删除关联
     * @param projectId
     */
    void deleteByProjectId (String projectId);

    /**
     * 根据分组编号删除关联
     * @param groupId
     */
    void deleteByGroupId (String groupId);

    /**
     * 查询关联用户编号
     * @param projectId
     * @return
     */
    @Query(value = "select group_id from coor_project_group where project_id = ?1", nativeQuery = true)
    List<String> findGroupByProjectId (String projectId);
}
